﻿<UserControl x:Class="Shatranj.ChessboardView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Shatranj="clr-namespace:Shatranj"
             HorizontalAlignment="Stretch"
             VerticalAlignment="Stretch"
             DataContext="{Binding ChessBoardViewModel}">

    <UserControl.Resources>
        <!--<Shatranj:ChessboardViewModel x:Key="ChessboardViewModel"/>-->
    </UserControl.Resources>

    <Grid>
        <ItemsControl ItemsSource="{Binding Path=BoardSquareViewModels, Mode=OneWay}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Shatranj:BoardSquareView />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                            <ColumnDefinition />
                            <ColumnDefinition />
                            <ColumnDefinition />
                            <ColumnDefinition />
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                    </Grid>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemContainerStyle>
                <!-- The content of ItemsPanelTemplate actually is inside a ContentPresenter -->
                <!-- Even the content of DataTemplate gets wrapped by a ContentPresenter -->
                <Style TargetType="{x:Type ContentPresenter}">
                    <Setter Property="Grid.Row" Value="{Binding Path=CurrentSquare.Location.X, Mode=TwoWay}" />
                    <Setter Property="Grid.Column" Value="{Binding Path=CurrentSquare.Location.Y, Mode=TwoWay}" />
                </Style>
            </ItemsControl.ItemContainerStyle>
        </ItemsControl>
    </Grid>
    <!--<Window.Resources>
        <Shatranj:ChessboardViewModel x:Key="ChessboardViewModel"/>
        <ResourceDictionary>
            <DataTemplate x:Key="BoardSquare">
                <Shatranj:BoardSquareView/>
            </DataTemplate> 
            <DataTemplate x:Key="Board">
                <Grid VerticalAlignment="Center" HorizontalAlignment="Center" DataContext="{StaticResource ChessboardViewModel}">
                    <Grid.RowDefinitions >
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                </Grid>
            </DataTemplate>
        </ResourceDictionary>
       
    </Window.Resources>-->


    <!--<Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>

        <Shatranj:BoardSquareView DataContext="{Binding Path=Board[a1]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[b1]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[c1]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[d1]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[e1]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[f1]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[g1]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[h1]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[a2]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[b2]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[c2]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[d2]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[e2]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[f2]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[g2]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[h2]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[a3]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[b3]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[c3]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[d3]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[e3]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[f3]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[g3]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[h3]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[a4]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[b4]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[c4]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[d4]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[e4]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[f4]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[g4]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[h4]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[a5]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[b5]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[c5]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[d5]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[e5]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[f5]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[g5]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[h5]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[a6]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[b6]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[c6]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[d6]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[e6]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[f6]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[g6]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[h6]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[a7]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[b7]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[c7]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[d7]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[e7]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[f7]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[g7]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[h7]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[a8]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[b8]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[c8]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[d8]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[e8]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[f8]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Bisque" DataContext="{Binding Path=Board[g8]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
        <Shatranj:BoardSquareView Background="Tan" DataContext="{Binding Path=Board[h8]}" Grid.Row="{Binding Path=Placement.X}" Grid.Column="{Binding Path=Placement.Y}"/>
    </Grid>-->
</UserControl>